// JobQueue.h

// Copyright (C) 2010  traxex

// Author: 	traxex <traxex@yahoo.cn>
// Created: 	24 Jun 2010
// Version: 	1.0

#pragma once
#include <queue>
#include <traxex/thread.h>

namespace traxex{
template<typename T>
class JobQueue{
  public:
    void push( const T &t){
        {
            unique_lock<mutex>	lock( mtx_);
            impl_.push( t);
        }
        cond_.notify_one();
    }

    T pop( ){
        unique_lock<mutex>	lock( mtx_);
        while( impl_.size() <= 0){
            cond_.wait( lock);
        }
        T tmp = impl_.front();
        impl_.pop();
        return tmp;
    }
  private:
    queue<T>		impl_;
    mutex		mtx_;
    condition_variable	cond_;
};
}

